from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-25 14:04:56.611780
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 25, May, 2022
Time: 14:05:02
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.4152
Nobs: 667.000 HQIC: -49.7874
Log likelihood: 8254.71 FPE: 1.88535e-22
AIC: -50.0228 Det(Omega_mle): 1.64902e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.309089 0.059941 5.157 0.000
L1.Burgenland 0.107951 0.038650 2.793 0.005
L1.Kärnten -0.109849 0.020310 -5.409 0.000
L1.Niederösterreich 0.201645 0.080442 2.507 0.012
L1.Oberösterreich 0.124301 0.079654 1.561 0.119
L1.Salzburg 0.256042 0.041097 6.230 0.000
L1.Steiermark 0.043895 0.053866 0.815 0.415
L1.Tirol 0.104365 0.043589 2.394 0.017
L1.Vorarlberg -0.063954 0.038517 -1.660 0.097
L1.Wien 0.031366 0.070487 0.445 0.656
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.042597 0.127620 0.334 0.739
L1.Burgenland -0.029940 0.082290 -0.364 0.716
L1.Kärnten 0.040258 0.043242 0.931 0.352
L1.Niederösterreich -0.181652 0.171270 -1.061 0.289
L1.Oberösterreich 0.447690 0.169592 2.640 0.008
L1.Salzburg 0.284727 0.087501 3.254 0.001
L1.Steiermark 0.107729 0.114686 0.939 0.348
L1.Tirol 0.314487 0.092806 3.389 0.001
L1.Vorarlberg 0.021344 0.082007 0.260 0.795
L1.Wien -0.039483 0.150074 -0.263 0.792
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182611 0.030853 5.919 0.000
L1.Burgenland 0.090545 0.019894 4.551 0.000
L1.Kärnten -0.008143 0.010454 -0.779 0.436
L1.Niederösterreich 0.255946 0.041406 6.181 0.000
L1.Oberösterreich 0.153566 0.041000 3.746 0.000
L1.Salzburg 0.043246 0.021154 2.044 0.041
L1.Steiermark 0.025884 0.027726 0.934 0.351
L1.Tirol 0.087013 0.022436 3.878 0.000
L1.Vorarlberg 0.052554 0.019826 2.651 0.008
L1.Wien 0.117700 0.036281 3.244 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110332 0.030812 3.581 0.000
L1.Burgenland 0.045947 0.019868 2.313 0.021
L1.Kärnten -0.014226 0.010440 -1.363 0.173
L1.Niederösterreich 0.185313 0.041351 4.481 0.000
L1.Oberösterreich 0.326929 0.040946 7.984 0.000
L1.Salzburg 0.101952 0.021126 4.826 0.000
L1.Steiermark 0.108965 0.027689 3.935 0.000
L1.Tirol 0.097118 0.022407 4.334 0.000
L1.Vorarlberg 0.059098 0.019799 2.985 0.003
L1.Wien -0.022358 0.036233 -0.617 0.537
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114486 0.057371 1.996 0.046
L1.Burgenland -0.043885 0.036993 -1.186 0.236
L1.Kärnten -0.046346 0.019439 -2.384 0.017
L1.Niederösterreich 0.140332 0.076994 1.823 0.068
L1.Oberösterreich 0.162642 0.076240 2.133 0.033
L1.Salzburg 0.281488 0.039336 7.156 0.000
L1.Steiermark 0.055874 0.051557 1.084 0.278
L1.Tirol 0.165606 0.041721 3.969 0.000
L1.Vorarlberg 0.094845 0.036866 2.573 0.010
L1.Wien 0.077107 0.067465 1.143 0.253
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059746 0.045284 1.319 0.187
L1.Burgenland 0.032341 0.029199 1.108 0.268
L1.Kärnten 0.051395 0.015344 3.350 0.001
L1.Niederösterreich 0.206242 0.060772 3.394 0.001
L1.Oberösterreich 0.317903 0.060177 5.283 0.000
L1.Salzburg 0.041328 0.031048 1.331 0.183
L1.Steiermark 0.008381 0.040694 0.206 0.837
L1.Tirol 0.131994 0.032931 4.008 0.000
L1.Vorarlberg 0.064936 0.029099 2.232 0.026
L1.Wien 0.086442 0.053251 1.623 0.105
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166338 0.054193 3.069 0.002
L1.Burgenland 0.008286 0.034944 0.237 0.813
L1.Kärnten -0.064985 0.018362 -3.539 0.000
L1.Niederösterreich -0.091339 0.072728 -1.256 0.209
L1.Oberösterreich 0.205299 0.072016 2.851 0.004
L1.Salzburg 0.053582 0.037156 1.442 0.149
L1.Steiermark 0.240329 0.048700 4.935 0.000
L1.Tirol 0.501857 0.039409 12.735 0.000
L1.Vorarlberg 0.058925 0.034823 1.692 0.091
L1.Wien -0.076240 0.063728 -1.196 0.232
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148562 0.060207 2.468 0.014
L1.Burgenland 0.003502 0.038821 0.090 0.928
L1.Kärnten 0.060051 0.020400 2.944 0.003
L1.Niederösterreich 0.181500 0.080800 2.246 0.025
L1.Oberösterreich -0.055635 0.080008 -0.695 0.487
L1.Salzburg 0.206689 0.041280 5.007 0.000
L1.Steiermark 0.134909 0.054105 2.493 0.013
L1.Tirol 0.070759 0.043783 1.616 0.106
L1.Vorarlberg 0.142618 0.038688 3.686 0.000
L1.Wien 0.108767 0.070800 1.536 0.124
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.373520 0.035531 10.512 0.000
L1.Burgenland -0.000045 0.022911 -0.002 0.998
L1.Kärnten -0.022142 0.012039 -1.839 0.066
L1.Niederösterreich 0.215797 0.047684 4.526 0.000
L1.Oberösterreich 0.226726 0.047217 4.802 0.000
L1.Salzburg 0.039494 0.024362 1.621 0.105
L1.Steiermark -0.015091 0.031930 -0.473 0.636
L1.Tirol 0.096258 0.025839 3.725 0.000
L1.Vorarlberg 0.053288 0.022832 2.334 0.020
L1.Wien 0.033912 0.041783 0.812 0.417
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037800 0.120477 0.174585 0.144533 0.102083 0.088033 0.041717 0.212447
Kärnten 0.037800 1.000000 -0.018556 0.135019 0.052864 0.090908 0.441533 -0.059911 0.093990
Niederösterreich 0.120477 -0.018556 1.000000 0.323668 0.131882 0.284045 0.077403 0.164281 0.302813
Oberösterreich 0.174585 0.135019 0.323668 1.000000 0.220514 0.309087 0.169821 0.151814 0.251799
Salzburg 0.144533 0.052864 0.131882 0.220514 1.000000 0.131008 0.099992 0.115715 0.131150
Steiermark 0.102083 0.090908 0.284045 0.309087 0.131008 1.000000 0.141777 0.120322 0.052668
Tirol 0.088033 0.441533 0.077403 0.169821 0.099992 0.141777 1.000000 0.071776 0.149277
Vorarlberg 0.041717 -0.059911 0.164281 0.151814 0.115715 0.120322 0.071776 1.000000 0.009014
Wien 0.212447 0.093990 0.302813 0.251799 0.131150 0.052668 0.149277 0.009014 1.000000